package controllers

import (
	"dog/models"
	beego "github.com/beego/beego/v2/server/web"
)

type Titlecontroller struct {
	beego.Controller
}

func (c *Titlecontroller) Add() {
	name := c.GetString("name")
	title := models.Title{
		Name: name,
	}

	err := models.DB.Create(&title).Error
	if err != nil {
		c.Data["json"] = Res{
			Code: 0,
			Msg:  "添加失败",
			Data: nil,
		}
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = Res{
			Code: 200,
			Msg:  "添加成功",
			Data: nil,
		}
		c.ServeJSON()
	}
}